/*
 * To change p template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.datalogic.define.dao.erp;

import com.openbravo.data.loader.TableDBSentenceBuilder;
import e.odbo.data.dao.ModifiedLogDAO;
import cn.ekuma.epos.db.table.erp.I_OrderType;

import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.serialize.DataRead;
import com.openbravo.data.loader.serialize.DataWrite;
import com.openbravo.data.loader.serialize.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.sentence.PreparedSentence;
import com.openbravo.data.loader.serialize.serializer.write.SerializerWriteString;
import com.openbravo.data.loader.table.TableDefinition;
import com.openbravo.format.Formats;
import com.openbravo.bean.erp.OrderType;
import com.openbravo.data.model.Field;

/**
 *
 * @author Administrator
 */
public class OrderTypeDAO extends ModifiedLogDAO<OrderType>{

    public OrderTypeDAO(I_Session s) {
        super(s);
    }

    @Override
    public TableDefinition getTable() {
        return new TableDefinition(
                "ORDERTYPES",
                new Field[]{
                   new Field(I_OrderType.ID,Datas.STRING, Formats.STRING),
                   new Field(I_OrderType.NAME,Datas.STRING, Formats.STRING),
                   new Field(I_OrderType.REVERSENAME,Datas.STRING, Formats.STRING),
                   new Field(I_OrderType.INOUTTYPE,Datas.INT, Formats.INT),
                   new Field(I_OrderType.PRICETYPE,Datas.INT, Formats.INT),
                   new Field(I_OrderType.CHANGEPRICE,Datas.BOOLEAN, Formats.BOOLEAN),
                   new Field(I_OrderType.CONSULTTYPE,Datas.INT, Formats.INT),
                   new Field(I_OrderType.SUBJETREFID,Datas.STRING, Formats.STRING),
                   new Field(I_OrderType.FUNDTYPE,Datas.INT, Formats.INT),
                   new Field(I_OrderType.ATTRIBUTESET_ID,Datas.STRING, Formats.STRING),
                   new Field(I_OrderType.ORDERLINETYPE,Datas.INT, Formats.INT),
                   new Field(I_OrderType.CASHADDABLE,Datas.BOOLEAN,  Formats.BOOLEAN),
                   new Field(I_OrderType.CATEGORY,Datas.STRING, Formats.STRING),
                   new Field(I_OrderType.INOUTTYPE1,Datas.INT, Formats.INT),
                   new Field(I_OrderType.STATEMACHINE,Datas.STRING, Formats.STRING),
                   new Field(I_OrderType.PRODUCTCONSULT,Datas.BOOLEAN, Formats.BOOLEAN),
                   new Field(I_OrderType.PROCESSNAME,Datas.STRING, Formats.STRING),
                   new Field(I_OrderType.SERVICECHECK,Datas.BOOLEAN, Formats.BOOLEAN),
                   new Field(I_OrderType.LASTMODIFIED,Datas.TIMESTAMP, Formats.TIMESTAMP),
                   new Field(I_OrderType.SELECTEDORDERPROCESS,Datas.STRING, Formats.STRING),
                   new Field(I_OrderType.CONSULTPRICETYPE,Datas.INT, Formats.INT),
                   new Field(I_OrderType.CHECKRULE,Datas.BOOLEAN, Formats.BOOLEAN)
                } ,
                new int[]{0});
    }

    @Override
    public void writeInsertValues(DataWrite dp, OrderType obj) throws BasicException {
          dp.setString(1,obj.getId());
          dp.setString(2,obj.getName());
          dp.setString(3,obj.getReverseName());
          dp.setInt(4,obj.getInOutType());
          dp.setInt(5,obj.getPriceType());
          dp.setBoolean(6,obj.isChangePrice());
          dp.setInt(7,obj.getConsultType());
          dp.setString(8,obj.getSubjectRefId());
          dp.setInt(9,obj.getFundType());
          dp.setString(10,obj.getAttributesetid());
          dp.setInt(11,obj.getOrderLineType());
          dp.setBoolean(12,obj.isCashAddAble());
          dp.setString(13,obj.getCategoryid());
          dp.setInt(14,obj.getInOutType1());
          dp.setString(15,obj.getStateMachine());
          dp.setBoolean(16,obj.isProductConsult());
          dp.setString(17,obj.getProcessName());
          dp.setBoolean(18,obj.isServiceCheck());
          dp.setTimestamp(19,obj.getLastModified());
          dp.setString(20,obj.getSelectedOrderProcess());
          dp.setInt(21,obj.getConsultPriceType());
          dp.setBoolean(22,obj.isCheckRule());
    }

    public OrderType readValues(DataRead dr,OrderType p) throws BasicException {
        if(p==null)
        	p=new OrderType();
        p.setId(dr.getString(1));
        p.setName(dr.getString(2));
        p.setReverseName(dr.getString(3));
        p.setInOutType(dr.getInt(4));
        p.setPriceType(dr.getInt(5));
        p.setChangePrice(dr.getBoolean(6));
        p.setConsultType(dr.getInt(7));
        p.setSubjectRefId(dr.getString(8));
        p.setFundType(dr.getInt(9));
        p.setAttributesetid(dr.getString(10));
        p.setOrderLineType(dr.getInt(11));
        p.setCashAddAble(dr.getBoolean(12));
        p.setCategoryid(dr.getString(13));
        p.setInOutType1(dr.getInt(14));
        p.setStateMachine(dr.getString(15));
        p.setProductConsult(dr.getBoolean(16));
        p.setProcessName(dr.getString(17));
        p.setServiceCheck(dr.getBoolean(18));
        p.setLastModified(dr.getTimestamp(19));
        p.setSelectedOrderProcess(dr.getString(20));
        p.setConsultPriceType(dr.getInt(21));
        p.setCheckRule(dr.getBoolean(22));
        return p;
    }

      public OrderType findOrderTypeById(String id) throws BasicException {
        return (OrderType) new PreparedSentence(s,((TableDBSentenceBuilder)getTableBuilder()).getListSQL(getTable())+" WHERE ID=?", SerializerWriteString.INSTANCE, this).find(id);
    }

    @Override
    public Class getSuportClass() {
        return OrderType.class;
    }
}
